package com.railway.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.railway.service.TrainService;
import com.railway.service.impl.TrainServiceImpl;
import com.railway.util.JSONUtil;

/**
 * Servlet implementation class TrainTimeServlet
 */
/**
 * 设置列车运行时间
 * @author 33676
 *
 */
@WebServlet("/TrainTimeServlet.do")
public class TrainTimeServlet extends HttpServlet {
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("Utf-8");
		int train_id = 0;
		String[] pass_time = null;
		String[] stading_time = null;
		
		if(request.getParameter("train_id") != null &&"".equals(request.getParameter("train_id"))) {
			train_id = Integer.parseInt(request.getParameter("train_id"));
		}
		
		if(request.getParameterValues("pass_time[]") != null &&"".equals(request.getParameter("pass_time[]"))) {
			pass_time = request.getParameterValues("pass_time[]");
		}
		
		if(request.getParameterValues("stading_time[]") != null &&"".equals(request.getParameter("stading_time[]"))) {
			pass_time = request.getParameterValues("stading_time[]");
		}
		
		TrainService ts = new TrainServiceImpl();
		JSONUtil.responJSOn(response, ts.settrainTime(train_id, pass_time, stading_time));
	}

}
